package com.bw.a1908.uitls.gfit.impl;


import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.bw.a1908.R;

/**
 * 数组View
 */
public class NumView extends LinearLayout {

    public NumView(Context context) {
        super(context);
        init();
    }

    public NumView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {

    }

    public int getCurrNum() {
        return currNum;
    }

    private int currNum;

    /**
     * 展示文字
     * 1908 -> 1909 复用+缓存
     */
    public void showNum(int num) {
        removeAllViews();
        currNum = num;
        if (num == 0){
            return;
        }
        char[] chars = String.valueOf(num).toCharArray();
        for (char c : chars) {
            addView(getNumView(c));
        }
    }

    public void showNumAdd() {
        showNum(++currNum);
    }

    /**
     * 单个文字View
     */
    private ImageView getNumView(char c) {
        ImageView numIv = new ImageView(getContext());
        switch (c) {
            default:
            case '0':
                numIv.setImageResource(R.mipmap.ca0);
                return numIv;
            case '1':
                numIv.setImageResource(R.mipmap.ca1);
                return numIv;
            case '2':
                numIv.setImageResource(R.mipmap.ca2);
                return numIv;
            case '3':
                numIv.setImageResource(R.mipmap.ca3);
                return numIv;
            case '4':
                numIv.setImageResource(R.mipmap.ca4);
                return numIv;
            case '5':
                numIv.setImageResource(R.mipmap.ca5);
                return numIv;
            case '6':
                numIv.setImageResource(R.mipmap.ca6);
                return numIv;
            case '7':
                numIv.setImageResource(R.mipmap.ca7);
                return numIv;
            case '8':
                numIv.setImageResource(R.mipmap.ca8);
                return numIv;
            case '9':
                numIv.setImageResource(R.mipmap.ca9);
                return numIv;
        }
    }
}
